package com.zhieasy.config;

import com.zhieasy.interceptors.InterceptorDo;
import com.zhieasy.service.StudentRedisService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * 拦截器配置
 * @author 风亦未止
 * @date 2021/11/20 21:11
 */
@Data
@Configuration
@ConfigurationProperties(prefix="intercept")
public class MvcConfig implements WebMvcConfigurer {
    @Autowired
    private StudentRedisService studentRedisService;

    /**
     * 拦截路径
     */
    private List<String> urls;
    @Bean
    public InterceptorDo interceptorDo(){
        return new InterceptorDo(studentRedisService);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(this.interceptorDo()).addPathPatterns(urls);
    }
}
